﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace hcrainMvc.DAL
{
	/// <summary>
	/// 数据访问类:yw_baseinfo
	/// </summary>
	public partial class yw_baseinfo
	{
		public yw_baseinfo()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(long id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from yw_baseinfo");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(hcrainMvc.Model.yw_baseinfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into yw_baseinfo(");
			strSql.Append("type,typename,mainname,maintype,fv1,fv2,fv3,fv4,fv5,fv6,fv7,fv8,fv9,fv10,nv1,nv2,nv3,nv4,nv5,nv6,nv7,nv8,nv9,nv10,dt1,dt2,dt3,dt4,dataadduserid,datadepid,databranchid,datadepname,databranchname,dataaddusername,dataaddtime)");
			strSql.Append(" values (");
			strSql.Append("@type,@typename,@mainname,@maintype,@fv1,@fv2,@fv3,@fv4,@fv5,@fv6,@fv7,@fv8,@fv9,@fv10,@nv1,@nv2,@nv3,@nv4,@nv5,@nv6,@nv7,@nv8,@nv9,@nv10,@dt1,@dt2,@dt3,@dt4,@dataadduserid,@datadepid,@databranchid,@datadepname,@databranchname,@dataaddusername,@dataaddtime)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@type", MySqlDbType.Int32,11),
					new MySqlParameter("@typename", MySqlDbType.VarChar,50),
					new MySqlParameter("@mainname", MySqlDbType.VarChar,200),
					new MySqlParameter("@maintype", MySqlDbType.Int32,11),
					new MySqlParameter("@fv1", MySqlDbType.VarChar,800),
					new MySqlParameter("@fv2", MySqlDbType.VarChar,800),
					new MySqlParameter("@fv3", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv4", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv5", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv6", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv7", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv8", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv9", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv10", MySqlDbType.VarChar,200),
					new MySqlParameter("@nv1", MySqlDbType.Double),
					new MySqlParameter("@nv2", MySqlDbType.Double),
					new MySqlParameter("@nv3", MySqlDbType.Double),
					new MySqlParameter("@nv4", MySqlDbType.Double),
					new MySqlParameter("@nv5", MySqlDbType.Double),
					new MySqlParameter("@nv6", MySqlDbType.Double),
					new MySqlParameter("@nv7", MySqlDbType.Double),
					new MySqlParameter("@nv8", MySqlDbType.Double),
					new MySqlParameter("@nv9", MySqlDbType.Double),
					new MySqlParameter("@nv10", MySqlDbType.Double),
					new MySqlParameter("@dt1", MySqlDbType.DateTime),
					new MySqlParameter("@dt2", MySqlDbType.DateTime),
					new MySqlParameter("@dt3", MySqlDbType.DateTime),
					new MySqlParameter("@dt4", MySqlDbType.DateTime),
					new MySqlParameter("@dataadduserid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepid", MySqlDbType.Int32,11),
					new MySqlParameter("@databranchid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepname", MySqlDbType.VarChar,100),
					new MySqlParameter("@databranchname", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddusername", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddtime", MySqlDbType.DateTime)};
			parameters[0].Value = model.type;
			parameters[1].Value = model.typename;
			parameters[2].Value = model.mainname;
			parameters[3].Value = model.maintype;
			parameters[4].Value = model.fv1;
			parameters[5].Value = model.fv2;
			parameters[6].Value = model.fv3;
			parameters[7].Value = model.fv4;
			parameters[8].Value = model.fv5;
			parameters[9].Value = model.fv6;
			parameters[10].Value = model.fv7;
			parameters[11].Value = model.fv8;
			parameters[12].Value = model.fv9;
			parameters[13].Value = model.fv10;
			parameters[14].Value = model.nv1;
			parameters[15].Value = model.nv2;
			parameters[16].Value = model.nv3;
			parameters[17].Value = model.nv4;
			parameters[18].Value = model.nv5;
			parameters[19].Value = model.nv6;
			parameters[20].Value = model.nv7;
			parameters[21].Value = model.nv8;
			parameters[22].Value = model.nv9;
			parameters[23].Value = model.nv10;
			parameters[24].Value = model.dt1;
			parameters[25].Value = model.dt2;
			parameters[26].Value = model.dt3;
			parameters[27].Value = model.dt4;
			parameters[28].Value = model.dataadduserid;
			parameters[29].Value = model.datadepid;
			parameters[30].Value = model.databranchid;
			parameters[31].Value = model.datadepname;
			parameters[32].Value = model.databranchname;
			parameters[33].Value = model.dataaddusername;
			parameters[34].Value = model.dataaddtime;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(hcrainMvc.Model.yw_baseinfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update yw_baseinfo set ");
			strSql.Append("type=@type,");
			strSql.Append("typename=@typename,");
			strSql.Append("mainname=@mainname,");
			strSql.Append("maintype=@maintype,");
			strSql.Append("fv1=@fv1,");
			strSql.Append("fv2=@fv2,");
			strSql.Append("fv3=@fv3,");
			strSql.Append("fv4=@fv4,");
			strSql.Append("fv5=@fv5,");
			strSql.Append("fv6=@fv6,");
			strSql.Append("fv7=@fv7,");
			strSql.Append("fv8=@fv8,");
			strSql.Append("fv9=@fv9,");
			strSql.Append("fv10=@fv10,");
			strSql.Append("nv1=@nv1,");
			strSql.Append("nv2=@nv2,");
			strSql.Append("nv3=@nv3,");
			strSql.Append("nv4=@nv4,");
			strSql.Append("nv5=@nv5,");
			strSql.Append("nv6=@nv6,");
			strSql.Append("nv7=@nv7,");
			strSql.Append("nv8=@nv8,");
			strSql.Append("nv9=@nv9,");
			strSql.Append("nv10=@nv10,");
			strSql.Append("dt1=@dt1,");
			strSql.Append("dt2=@dt2,");
			strSql.Append("dt3=@dt3,");
			strSql.Append("dt4=@dt4,");
			strSql.Append("dataadduserid=@dataadduserid,");
			strSql.Append("datadepid=@datadepid,");
			strSql.Append("databranchid=@databranchid,");
			strSql.Append("datadepname=@datadepname,");
			strSql.Append("databranchname=@databranchname,");
			strSql.Append("dataaddusername=@dataaddusername,");
			strSql.Append("dataaddtime=@dataaddtime");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@type", MySqlDbType.Int32,11),
					new MySqlParameter("@typename", MySqlDbType.VarChar,50),
					new MySqlParameter("@mainname", MySqlDbType.VarChar,200),
					new MySqlParameter("@maintype", MySqlDbType.Int32,11),
					new MySqlParameter("@fv1", MySqlDbType.VarChar,800),
					new MySqlParameter("@fv2", MySqlDbType.VarChar,800),
					new MySqlParameter("@fv3", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv4", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv5", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv6", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv7", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv8", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv9", MySqlDbType.VarChar,200),
					new MySqlParameter("@fv10", MySqlDbType.VarChar,200),
					new MySqlParameter("@nv1", MySqlDbType.Double),
					new MySqlParameter("@nv2", MySqlDbType.Double),
					new MySqlParameter("@nv3", MySqlDbType.Double),
					new MySqlParameter("@nv4", MySqlDbType.Double),
					new MySqlParameter("@nv5", MySqlDbType.Double),
					new MySqlParameter("@nv6", MySqlDbType.Double),
					new MySqlParameter("@nv7", MySqlDbType.Double),
					new MySqlParameter("@nv8", MySqlDbType.Double),
					new MySqlParameter("@nv9", MySqlDbType.Double),
					new MySqlParameter("@nv10", MySqlDbType.Double),
					new MySqlParameter("@dt1", MySqlDbType.DateTime),
					new MySqlParameter("@dt2", MySqlDbType.DateTime),
					new MySqlParameter("@dt3", MySqlDbType.DateTime),
					new MySqlParameter("@dt4", MySqlDbType.DateTime),
					new MySqlParameter("@dataadduserid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepid", MySqlDbType.Int32,11),
					new MySqlParameter("@databranchid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepname", MySqlDbType.VarChar,100),
					new MySqlParameter("@databranchname", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddusername", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddtime", MySqlDbType.DateTime),
					new MySqlParameter("@id", MySqlDbType.Int64,20)};
			parameters[0].Value = model.type;
			parameters[1].Value = model.typename;
			parameters[2].Value = model.mainname;
			parameters[3].Value = model.maintype;
			parameters[4].Value = model.fv1;
			parameters[5].Value = model.fv2;
			parameters[6].Value = model.fv3;
			parameters[7].Value = model.fv4;
			parameters[8].Value = model.fv5;
			parameters[9].Value = model.fv6;
			parameters[10].Value = model.fv7;
			parameters[11].Value = model.fv8;
			parameters[12].Value = model.fv9;
			parameters[13].Value = model.fv10;
			parameters[14].Value = model.nv1;
			parameters[15].Value = model.nv2;
			parameters[16].Value = model.nv3;
			parameters[17].Value = model.nv4;
			parameters[18].Value = model.nv5;
			parameters[19].Value = model.nv6;
			parameters[20].Value = model.nv7;
			parameters[21].Value = model.nv8;
			parameters[22].Value = model.nv9;
			parameters[23].Value = model.nv10;
			parameters[24].Value = model.dt1;
			parameters[25].Value = model.dt2;
			parameters[26].Value = model.dt3;
			parameters[27].Value = model.dt4;
			parameters[28].Value = model.dataadduserid;
			parameters[29].Value = model.datadepid;
			parameters[30].Value = model.databranchid;
			parameters[31].Value = model.datadepname;
			parameters[32].Value = model.databranchname;
			parameters[33].Value = model.dataaddusername;
			parameters[34].Value = model.dataaddtime;
			parameters[35].Value = model.id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(long id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from yw_baseinfo ");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from yw_baseinfo ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.yw_baseinfo GetModel(long id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,type,typename,mainname,maintype,fv1,fv2,fv3,fv4,fv5,fv6,fv7,fv8,fv9,fv10,nv1,nv2,nv3,nv4,nv5,nv6,nv7,nv8,nv9,nv10,dt1,dt2,dt3,dt4,dataadduserid,datadepid,databranchid,datadepname,databranchname,dataaddusername,dataaddtime from yw_baseinfo ");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			hcrainMvc.Model.yw_baseinfo model=new hcrainMvc.Model.yw_baseinfo();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.yw_baseinfo DataRowToModel(DataRow row)
		{
			hcrainMvc.Model.yw_baseinfo model=new hcrainMvc.Model.yw_baseinfo();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=long.Parse(row["id"].ToString());
				}
				if(row["type"]!=null && row["type"].ToString()!="")
				{
					model.type=int.Parse(row["type"].ToString());
				}
				if(row["typename"]!=null)
				{
					model.typename=row["typename"].ToString();
				}
				if(row["mainname"]!=null)
				{
					model.mainname=row["mainname"].ToString();
				}
				if(row["maintype"]!=null && row["maintype"].ToString()!="")
				{
					model.maintype=int.Parse(row["maintype"].ToString());
				}
				if(row["fv1"]!=null)
				{
					model.fv1=row["fv1"].ToString();
				}
				if(row["fv2"]!=null)
				{
					model.fv2=row["fv2"].ToString();
				}
				if(row["fv3"]!=null)
				{
					model.fv3=row["fv3"].ToString();
				}
				if(row["fv4"]!=null)
				{
					model.fv4=row["fv4"].ToString();
				}
				if(row["fv5"]!=null)
				{
					model.fv5=row["fv5"].ToString();
				}
				if(row["fv6"]!=null)
				{
					model.fv6=row["fv6"].ToString();
				}
				if(row["fv7"]!=null)
				{
					model.fv7=row["fv7"].ToString();
				}
				if(row["fv8"]!=null)
				{
					model.fv8=row["fv8"].ToString();
				}
				if(row["fv9"]!=null)
				{
					model.fv9=row["fv9"].ToString();
				}
				if(row["fv10"]!=null)
				{
					model.fv10=row["fv10"].ToString();
				}
					//model.nv1=row["nv1"].ToString();
					//model.nv2=row["nv2"].ToString();
					//model.nv3=row["nv3"].ToString();
					//model.nv4=row["nv4"].ToString();
					//model.nv5=row["nv5"].ToString();
					//model.nv6=row["nv6"].ToString();
					//model.nv7=row["nv7"].ToString();
					//model.nv8=row["nv8"].ToString();
					//model.nv9=row["nv9"].ToString();
					//model.nv10=row["nv10"].ToString();
				if(row["dt1"]!=null && row["dt1"].ToString()!="")
				{
					model.dt1=DateTime.Parse(row["dt1"].ToString());
				}
				if(row["dt2"]!=null && row["dt2"].ToString()!="")
				{
					model.dt2=DateTime.Parse(row["dt2"].ToString());
				}
				if(row["dt3"]!=null && row["dt3"].ToString()!="")
				{
					model.dt3=DateTime.Parse(row["dt3"].ToString());
				}
				if(row["dt4"]!=null && row["dt4"].ToString()!="")
				{
					model.dt4=DateTime.Parse(row["dt4"].ToString());
				}
				if(row["dataadduserid"]!=null && row["dataadduserid"].ToString()!="")
				{
					model.dataadduserid=int.Parse(row["dataadduserid"].ToString());
				}
				if(row["datadepid"]!=null && row["datadepid"].ToString()!="")
				{
					model.datadepid=int.Parse(row["datadepid"].ToString());
				}
				if(row["databranchid"]!=null && row["databranchid"].ToString()!="")
				{
					model.databranchid=int.Parse(row["databranchid"].ToString());
				}
				if(row["datadepname"]!=null)
				{
					model.datadepname=row["datadepname"].ToString();
				}
				if(row["databranchname"]!=null)
				{
					model.databranchname=row["databranchname"].ToString();
				}
				if(row["dataaddusername"]!=null)
				{
					model.dataaddusername=row["dataaddusername"].ToString();
				}
				if(row["dataaddtime"]!=null && row["dataaddtime"].ToString()!="")
				{
					model.dataaddtime=DateTime.Parse(row["dataaddtime"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,type,typename,mainname,maintype,fv1,fv2,fv3,fv4,fv5,fv6,fv7,fv8,fv9,fv10,nv1,nv2,nv3,nv4,nv5,nv6,nv7,nv8,nv9,nv10,dt1,dt2,dt3,dt4,dataadduserid,datadepid,databranchid,datadepname,databranchname,dataaddusername,dataaddtime ");
			strSql.Append(" FROM yw_baseinfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM yw_baseinfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from yw_baseinfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "yw_baseinfo";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

